package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.FFlibraryGoldLectureListBean;
import com.fancy.learncenter.ui.activity.GoldLecturerActivity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;
import com.fancy.learncenter.utils.ImgFilter;
import com.fancy.learncenter.utils.StrUtil;
import com.fancy.learncenter.utils.Utils;

import java.util.List;

/**
 * Created by shiweiwei on 2017/4/21.
 */

public class GoldLectureListAdapter extends CommonRecycleViewAdapter<FFlibraryGoldLectureListBean.ResultBean>{
    Context mContext;
    public GoldLectureListAdapter(Context mContext, List<FFlibraryGoldLectureListBean.ResultBean> itemDatas) {
        super(mContext, R.layout.gold_lecture_list_item, itemDatas);
        this.mContext = mContext;
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final FFlibraryGoldLectureListBean.ResultBean item, int position) {

        SimpleDraweeView headerIcon = customViewHold.getView(R.id.headerIcon);
        TextView headName = customViewHold.getView(R.id.headerName);
        TextView lectureLevel = customViewHold.getView(R.id.lecture_level_text);
        TextView decription = customViewHold.getView(R.id.decription);
        TextView listenNum = customViewHold.getView(R.id.listen_num);
        TextView anchorCertification = customViewHold.getView(R.id.label_anchor_certification);
        headerIcon.setImageURI(Utils.getImgUri(item.getUserPath()+ ImgFilter.SSCC_H200));
        headName.setText(item.getNickName());
        int memberType = StrUtil.checkUserType(item.getMemberType());
        lectureLevel.setText(StrUtil.getMemberType(memberType));
        if (memberType >= 8){
            anchorCertification.setVisibility(View.GONE);
            lectureLevel.setVisibility(View.VISIBLE);
            lectureLevel.setBackgroundResource(R.drawable.label_yellow_shape);
        }else if (memberType < 8 && memberType >= 5){
            anchorCertification.setVisibility(View.GONE);
            lectureLevel.setVisibility(View.VISIBLE);
            switch (memberType){
                case 5:
                    lectureLevel.setBackgroundResource(R.drawable.label_yellow_shape);
                    break;
                case 6:
                    lectureLevel.setBackgroundResource(R.drawable.label_orange_shape);
                    break;
                case 7:
                    lectureLevel.setBackgroundResource(R.drawable.label_green_shape);
                    break;
            }
        }else if (memberType == 4){
            anchorCertification.setVisibility(View.VISIBLE);
            lectureLevel.setVisibility(View.GONE);
        }else {
            anchorCertification.setVisibility(View.GONE);
            lectureLevel.setVisibility(View.GONE);
        }

        decription.setText(item.getIntroduction());
        listenNum.setText(StrUtil.formatPlayNum(item.getPlayCount()));

        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                     Intent intent = new Intent(mContext, GoldLecturerActivity.class);
                intent.putExtra("fid",item.getFancyId());
                intent.putExtra("nick_name",item.getNickName());
                mContext.startActivity(intent);

            }
        });

    }
}
